local gojiao = fk.CreateSkill {
    name = "gojiao",
    anim_type = "defensive",
    tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["gojiao"] = "狗叫",
  ["$gojiao1"] = "你在狗叫什么",
  [":gojiao"] = "锁定技，你对角色牌上有“狗”的角色使用牌无距离无次数限制，当有“狗”的角色对你使用【杀】时，需弃置一张基本牌；其他角色回合结束时，若其武将牌有“狗”且本回合未对你造成伤害，你摸一张牌。",
  ["#gojiao-discard"] = "狗叫：你需要弃置一张基本牌",
}

-- 有"狗"的角色对你使用【杀】时，需额外弃置一张基本牌
gojiao:addEffect(fk.CardUsing,{
  can_trigger = function(self, event, target, player, data)
    local qizhi = false
    local handcards = data.from:getCardIds("h")
    for _, _id in ipairs(handcards) do
        if Fk:getCardById(_id).type == Card.TypeBasic then
            qizhi = true
        end
    end

    return player:hasSkill(gojiao.name) and
           data.card.trueName == "slash" and #data.from:getPile("dog") > 0 and
           table.contains(data.tos, player) and qizhi
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = target
    
    room:askToDiscard(data.from, {
        min_num = 1,
        max_num = 1,
        cancelable = false,
        include_equip = false,
        pattern = ".|.|.|.|.|basic",
        prompt = "#gojiao-discard",
        skill_name = gojiao.name,
    })
  end,
})

-- 其他角色回合结束时，若其有"狗"且未对你造成伤害，你摸一张牌
gojiao:addEffect(fk.TurnEnd,{
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(gojiao.name) and target ~= player then 
    
        return #player.room.logic:getActualDamageEvents(1, function(e)
            local damage = e.data
            return damage.to == player
        end, Player.HistoryTurn) == 0 and #player.room.current:getPile("dog") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1)
  end,
})

gojiao:addEffect("targetmod", {
      bypass_times = function(self, player, skill, scope, card, to)
        return player:hasSkill(gojiao.name) and card and to and #to:getPile("dog") > 0
      end,
      bypass_distances =  function(self, player, skill, card, to)
        return player:hasSkill(gojiao.name) and card and to and #to:getPile("dog") > 0
      end,
  })

return gojiao 